from django.db import models

# Create your models here.
from django.contrib.auth.models import AbstractUser
from datetime import datetime


class UserProfile(AbstractUser):
    nick_name = models.CharField(max_length=50, verbose_name='昵称', default='')
    birthday = models.DateField(verbose_name='生日', null=True, blank=True)
    gender = models.CharField(max_length=5, choices=(('male', u'男'), ('female', u'女')), default=u'女')
    address = models.CharField(max_length=100, verbose_name='地址', default=u'')
    mobile = models.CharField(max_length=11, verbose_name='手机号', null=True, blank=True)
    image = models.ImageField(upload_to='image/%Y/%m', default=u'image/default.png', max_length=100)
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.username


class EmailVerifyRecord(models.Model):
    code = models.CharField(max_length=20, verbose_name=u'验证码')
    email = models.EmailField(max_length=50, verbose_name=u'邮箱')
    send_type = models.CharField(choices=(('register', u'注册'), ('forget', u'找回密码')),max_length=100)
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = u'邮箱验证码'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '{0}:{1}'.format(self.email, self.code)


class Banner(models.Model):
    title = models.CharField(max_length=100, verbose_name=u'标题')
    image = models.ImageField(upload_to='banner/%Y/%m',verbose_name=u'轮播图', max_length=100)
    url = models.URLField(max_length=200, verbose_name=u'访问地址')
    index = models.IntegerField(default=100,verbose_name=u'顺序')
    createUser = models.IntegerField(verbose_name=u'创建人', null=True, blank=True)
    create_time = models.DateTimeField(default=datetime.now, verbose_name=u'创建时间')
    updateUser = models.IntegerField(verbose_name=u'更新人', null=True, blank=True)
    update_time = models.DateTimeField(null=True, verbose_name=u'更新时间')
    deleted = models.BooleanField(default=False, verbose_name=u'是否删除')

    class Meta:
        verbose_name = u'轮播图'
        verbose_name_plural = verbose_name
